

<template>
  <van-dialog v-model:show="show" title="设置单词熟练度" show-cancel-button show-confirm-button
              @confirm="()=>{
                changeLevel();
              }"
              @cancel="()=>{
                show=false;
              }"
  >
    <div class="f-row f-center" style="width:100%;  ">
      <el-text size="large" style="font-size:30px;">{{word.content}}</el-text>
    </div>
    <div class="f-col f-center">
      <div class="f-row f-center" style="width:100%; margin-top:20px; margin-bottom: 20px;">
        <van-rate
            v-model="rate"
            :size="30"
            :count="6"
            color="#ffd21e"
            void-icon="star"
            void-color="#eee"
        />
      </div>
      <div class="f-row f-center" style="width:100%;  margin-bottom: 20px;">
          <el-text size="large">{{config.levelRate[rate]}}
            <el-text type="danger" tag="ins" @click="()=>{
              removeWords();

            }">删除</el-text>
          </el-text>
      </div>
    </div>


  </van-dialog>
</template>
<script setup>
import {ref,defineExpose} from 'vue';
import config from "../../../config";
import {changeWordLevel, getMyOneWordMessage, removeWord} from "@/apis/apis";
import ret from "@/utils/ret";
import word_logic from "@/pages/wordPage/src/word_logic";
let show=ref(false);
let rate=ref(6);
let resFun=()=>{}
let word=ref({
  "content": "residential",
  "des": "adj. 住宅的；与居住有关的\r"
})
defineExpose({
  apply:function (fun,e){
    word.value=e;
    show.value=true;
    console.log(e);
    resFun=fun;
    rate.value=e.level;
  }
})
function removeWords(){
  removeWord({
    "content": [
        word.value.content
    ]
  }).then(d=>{
    ret.showRetMessage(d);
    if (d.data.code!=-1){
      resFun();
      show.value=false;
      word_logic.removeWord(word.value.content)
    }
  })
}
function changeLevel(){
  changeWordLevel({
    "content": [
      word.value.content
    ],
    "level": rate.value
  }).then(d=>{
    ret.showRetMessage(d);
    if (d.data.code!=-1){
      show.value=false;
      word_logic.changeWord(word.value.content,word.value.des,rate.value)
    }
  })
}
</script>
<style scoped>

</style>